# -*- coding: utf-8 -*-
from pymongo import MongoClient


class MongoSource:

    def __init__(self, host: str, port=27017) -> None:
        super().__init__()
        self.conn = MongoClient(host, port)

    def insert_record(self, record: dict) -> None:
        db = self.conn.draft_db
        clt = db.test_collection
        clt.insert(record)
        print('insert record success')

    def find_record(self, param: dict) -> None:
        ctl = self.conn.draft_db.test_collection
        ret = ctl.find(param)
        rtl = [i for i in ret]
        print('find ret', rtl, 'ret type', type(ret))
        self.conn.close()




if __name__ == '__main__':
    source = MongoSource('localhost', 27017)
    # source.insert_record({'name':'周杰伦', 'age':40})
    source.find_record({'name': 'fujianjian'})
